# # # # # # # # #
# perm(moves,n) is a function for creating factorials on the basis of row number
perm=function(moves,n=4){
elements=1:n;output=rep(NA,n)
for(i in 1:n)
{output[i]=elements[((moves - ((factorial(n+1-i)) * (moves%/%factorial(n+1-i)))) %/% factorial(n-i))+1]
elements=elements[-(((moves -((factorial(n+1-i)) * (moves%/%factorial(n+1-i)))) %/% factorial(n-i))+1)]}
return(output)}
sink("solutions1e92e9.txt")
for(rownr in (1e9+1):2e9){output=rep(NA,16);elements=1:16
for(i in 16){
{output[i]=elements[((rownr - ((factorial(17-i)) * (rownr%/%factorial(17-i)))) %/% factorial(16-i))+1]
elements=elements[-(((rownr -((factorial(17-i)) * (rownr%/%factorial(17-i)))) %/% factorial(16-i))+1)]}}
{if(is.null(exclude(output))) print(output)}}
sink()
exclude=function(x){
for(i in 1:(length(x)-1))
if(x[i]==1&x[i+1]%in%c(3,4,7:16) |
x[i]==2&x[i+1]%in%c(4,8:16) |
x[i]==3&x[i+1]%in%c(5,9:16) |
x[i]==4&x[i+1]%in%c(1,2,5,6,9:16) |
x[i]==5&x[i+1]%in%c(3,4,7,8,11:16) |
x[i]==6&x[i+1]%in%c(4,8,12:16) |
x[i]==7&x[i+1]%in%c(1,5,9,13:16) |
x[i]==8&x[i+1]%in%c(1,2,5,6,9,10,13:16) |
x[i]==9&x[i+1]%in%c(1:4,7,8,11,12,15,16) |
x[i]==10&x[i+1]%in%c(1:4,8,12,16) |
x[i]==11&x[i+1]%in%c(1:5,13) |
x[i]==12&x[i+1]%in%c(1:6,9,10,13,14) |
x[i]==13&x[i+1]%in%c(1:8,11,12,15,16) |
x[i]==14&x[i+1]%in%c(1:8,12,16) |
x[i]==15&x[i+1]%in%c(1:9,13) |
x[i]==16&x[i+1]%in%c(1:10,13,14))
return(0)}
exclude.vector=sapply(1:length(perm.list),function(x){ifelse(is.null(exclude(perm.list[[x]])),"yes","no")})
results.matrix=do.call(rbind,perm.list[which(exclude.vector=="yes")])
# In the first 1e8 permuations there are 611 orders that are valid.
# In the first 1e7 permuations there are 611 orders that are valid. So these can be skipped.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.